﻿using System.Diagnostics;

namespace KinonekoSoftware.Extensions.Strings.SearchModels
{
    [DebuggerDisplay("match:{IsMatch}  [{Offset}, {Length}]")]
    public class MatchResult(int offset, int len, bool r)
    {
        public string CreateString(string input)
        {
            if(input == null)
            {
                return string.Empty;
            }

            if(Offset >= input.Length ||
                Offset + Length > input.Length)
            {
                return string.Empty;
            }

            return new string((input.AsSpan().Slice(Offset, Length)));
        }

        public readonly int  Offset  = offset;
        public readonly int  Length  = len;
        public readonly bool IsMatch = r; 
    }
}